﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nizm0.QOT.Library.Objects
{
    public class ListOfVariable : List<Variable>, IList<Variable>, IEnumerable<Variable>
    {
        /// <summary>
        /// Verify if contains element "Variable" by his name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool Contains(string name)
        {
            foreach (Variable var in this)
            {
                if (name == var.Name)
                    return true;
            }
            return false;
        }

        public int IndexOf(string name)
        {
            foreach (Variable var in this)
            {
                if (var.Name == name) return this.IndexOf(var);
            }
            return -1;
        }

        public bool Remove(string name)
        {
            foreach (Variable var in this)
            {
                if (name == var.Name)
                {
                    this.Remove(var);
                    return true;
                }
            }
            return false;
        }

        public bool RemoveExcept(List<string> names)
        {
            foreach (Variable var in this)
            {
                if (!names.Contains(var.Name))
                {
                    this.Remove(var);
                    return true;
                }
            }
            return false;
        }
        //#region IList<VariableFromQuery> Members

        //public int IndexOf(VariableFromQuery item)
        //{
        //    throw new NotImplementedException();
        //}

        //public void Insert(int index, VariableFromQuery item)
        //{
        //    throw new NotImplementedException();
        //}

        //public void RemoveAt(int index)
        //{
        //    throw new NotImplementedException();
        //}

        //public VariableFromQuery this[int index]
        //{
        //    get
        //    {
        //        throw new NotImplementedException();
        //    }
        //    set
        //    {
        //        throw new NotImplementedException();
        //    }
        //}

        //#endregion

        //#region ICollection<VariableFromQuery> Members

        //public void Add(VariableFromQuery item)
        //{
        //    throw new NotImplementedException();
        //}

        //public void Clear()
        //{
        //    throw new NotImplementedException();
        //}

        //public bool Contains(VariableFromQuery item)
        //{
        //    throw new NotImplementedException();
        //}

        //public void CopyTo(VariableFromQuery[] array, int arrayIndex)
        //{
        //    throw new NotImplementedException();
        //}

        //public int Count
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //public bool IsReadOnly
        //{
        //    get { throw new NotImplementedException(); }
        //}

        //public bool Remove(VariableFromQuery item)
        //{
        //    throw new NotImplementedException();
        //}

        //#endregion

        //#region IEnumerable<VariableFromQuery> Members

        //public IEnumerator<VariableFromQuery> GetEnumerator()
        //{
        //    throw new NotImplementedException();
        //}

        //#endregion

        //#region IEnumerable Members

        //System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        //{
        //    throw new NotImplementedException();
        //}

        //#endregion

        public Variable this[string name]
        {
            get
            {
                foreach (Variable var in this)
                {
                    if (var.Name == name)
                        return var;
                }
                return null;
            }
        }

        public Variable this[Variable var]
        {
            get
            {
                foreach (Variable tmpvar in this)
                    if (tmpvar == var)
                        return tmpvar;
                return null;
            }
        }
    }
}
